<template>
  <div :class="['halert', `halert-${type}`, `halert-${size}`]">
    <div class="halert--left-line"></div>
    <h1 @click="$emit('toDetail')" :class="['halert--h1', isLook ? 'ellipsis-2' : 'ellipsis-2']" :style="{width: tip || showRight ? '86%' : (isLook ? '78%' : '96%' ) }">
      {{ title | htmlFilter }}
    </h1>
    <div class="h-list-item--cz" v-if="isLook" @click="$emit('handle')">
      <img :src="require('@/assets/Image/handclick.png')" width="12px" alt="" />
      进行处置</div>
    <div class="right-time" v-if="showRight">
      {{ source }} {{ createTime }}
    </div>
    <div v-if="showImage" :class="['right-img', imgIcon ? '' : 'right-img-grav']">
      <a-tooltip :title="imgIcon ? '该事件包含图片' : '该事件没有图片'">
        <SvgIcon iconClass="color-image" @click="showImageModal(imgIcon)" />
      </a-tooltip>
    </div>
    <div class="halert--tip" v-if="tip">{{ tip }}</div>
    <div class="halert--footer" v-if="!showDesc">
      <span>事件编号</span>
      <a-divider type="vertical"></a-divider>
      <span>{{ no || '无' }}</span>
      <span class="halert--footer-blue">
        <span>已发指令 {{ sendNum }}</span>
        <a-divider type="vertical"></a-divider>
        <span>回复指令 {{ replyNum }}</span>
      </span>
    </div>
    <div v-else-if="showDescribe" class="halert--footer ellipsis-2" style="margin-top: -8px;line-height: 1.2;">
      <p>{{ desc }}</p>
    </div>
    <div class="halert--footer ellipsis-2" style="margin-top: 4px" v-else>
      <p>{{ desc }}</p>
    </div>

    <a-button @click="$emit('toDetail')" v-if="showDetailBtn" size="small" :type="type" :class="['halert--footer-btn', type =='primary' ? 'ant-btn-b' : '']">
      查看详情
    </a-button>

    <a-modal v-model="showModal" width="900px" title="图片预览">
      <div class="imgbg scroll">
        <img :src="url" width="100%" alt="" />
      </div>

      <template slot="footer">
        <a-button type="default" @click="showModal = false">关闭</a-button>
      </template>
    </a-modal>
  </div>
</template>
<script>
import SvgIcon from '@/components/SvgIcon';

export default {
  name: 'HAlert',
  components: { SvgIcon },
  props: {
    size: {
      type: String,
      default: 'default'
    },
    // 是观察事件
    isLook: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'primary'
    },
    title: {
      type: String,
      default: ''
    },
    tip: {
      type: String,
      default: ''
    },
    desc: {
      type: String,
      default: ''
    },
    source: {
      type: String,
      default: ''
    },
    createTime: {
      type: String,
      default: ''
    },
    sendNum: {
      type: [String, Number],
      default: 0
    },
    replyNum: {
      type: [String, Number],
      default: 0
    },
    no: {
      type: String,
      default: '202262101'
    },
    showDesc: {
      type: Boolean,
      default: false
    },
    showDetailBtn: {
      type: Boolean,
      default: true
    },
    showDescribe: {
      type: Boolean,
      default: true
    },
    hideTag: {
      type: Boolean,
      default: true
    },
    showRight: {
      type: Boolean,
      default: false
    },
    imgIcon: {
      type: String,
      default: ''
    },
    showImage: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      showModal: false,
      url: ''
    };
  },
  methods: {
    showImageModal(url) {
      if (!url) return;
      this.url = url;
      this.showModal = true;
    }
  }
};
</script>
<style lang="less" scoped>
.imgbg {
  max-height: 600px;
  overflow-y: auto;
}
.halert {
  padding: 9px 16px;
  box-sizing: border-box;
  box-shadow: 0px 3px 29px 0px rgba(196,203,214,0.1000);
  position: relative;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 14px;
  min-height: 90px;
  &:first-child {
    margin-top: 0;
  }
  &.halert-large {
    margin-bottom: 24px;
    padding: 9px 20px;
    &:last-child {
      margin-bottom: 0;
    }
    > h1 {
      font-size: 16px;
    }
    .halert--footer {
      font-size: 14px;
    }
    p {
      width: 96%;
    }
  }

  .halert--left-line {
    width: 4px;
    height: 90%;
    border-radius: 20px;
    position: absolute;
    left: 17px;
    top: 5%;
  }

  > h1 {
    font-size: 15px;
    font-weight: 400;
    color: #0A1629;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    width: 86%;
    margin-left: 14px;
  }

  .halert--tip {
    width: 38px;
    height: 18px;
    position: absolute;
    right: 0;
    top: 0;
    font-size: 12px;
    font-weight: 400;
    color: #FFFFFF;
    line-height: 16px;
    text-align: center;
  }

  .halert--footer {
    margin-top: 13px;
    color: #91929E;
    font-size: 12px;
    margin-left: 14px;
  }

  .halert--footer-blue {
    margin-left: 10px;
    color: #3F8CFF;
    > span {
      cursor: pointer;
    }
  }

  .halert--footer-btn {
    position: absolute;
    right: 16px;
    bottom: 6px;
    font-size: 12px;
  }

  &.halert-primary {
    background: rgba(63, 140, 255, 0.0500);
    .halert--left-line {
      background: #3F8CFF;
    }
    .halert--tip {
      background: #3F8CFF;
      border: 1px solid #3184FA;
    }
  }

  &.halert-danger {
    background: rgba(246, 8, 8, 0.0500);
    .halert--left-line {
      background: #FF0000;
    }
    .halert--tip {
      background: #FF0000;
      border: 1px solid #FF0000;
    }
    .halert--footer-blue {
      color: #FF0000;
    }
  }

  .halert--h1 {
    height: 42px;
    cursor: pointer;
    &:hover {
      color: #3184FA;

    }
  }

  @media (max-width: 1600px) {
    .halert--left-line {
      left: 0;
    }
    > h1{
      margin-left: 0;
    }
    .halert--footer {
      margin-left: 0;
    }
  }
}
.right-time {
  position: absolute;
  right: 12px;
  font-size: 12px;
  top: 12px;
}
.right-img {
  position: absolute;
  right: 12px;
  font-size: 24px;
  bottom: 8px;
  cursor: pointer;
  border: none;
  .svg-icon {
    border: 0 solid #000;
    outline: none;
  }
}
.right-img-grav {
  -webkit-filter: grayscale(100%);

  -moz-filter: grayscale(100%);

  -ms-filter: grayscale(100%);

  -o-filter: grayscale(100%);

  filter: grayscale(100%);

  filter: gray;
}
.h-list-item--cz {
  min-width: 72px;
  height: 22px;
  background: #EBEFF4;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  color: #7A879C;
  line-height: 22px;
  text-align: center;
  position: absolute;
  right: 4px;
  top: 10px;
  cursor: pointer;
  transform: scale(0.9);
  transition: all 0.3s;
  &:hover {
    background: #d7dadf;
    color: #546683;
  }
  img {
    // position: absolute;
    // left: -24px;
    // height: auto;
    height: 16px;
    margin-top: -5px;
    margin-right: 4px;
  }
}
</style>
